package com.jintoufs.weixin.placard;

import com.jintoufs.domain.constants.Constants;
import com.jintoufs.domain.scene.Scene;
import com.jintoufs.domain.scene.SceneTicket;
import com.jintoufs.domain.sys.Dictionary;
import com.jintoufs.service.scene.SceneService;
import com.jintoufs.service.scene.SceneTicketService;
import com.jintoufs.service.sys.DictionaryService;
import com.jintoufs.util.valid.ValidUtil;
import org.cosmos.modules.web.msg.AjaxMsg;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Scope("prototype")
@RequestMapping("/api/setting")
public class PlacardAction {

    @Resource
    private DictionaryService dictionaryService;
    @Resource
    private SceneTicketService sceneTicketService;

    @RequestMapping("/placard")
    @ResponseBody
    public AjaxMsg detail(String type, String goodsId) {
        AjaxMsg ajaxMsg = new AjaxMsg();
        ajaxMsg.setCode(AjaxMsg.SUCCESS);
        if (Constants.PLACARD_SCENE.equals(type)) {
            Map map = new HashMap();
            map.put("sceneId", goodsId);
            List<Map<String, Object>> scenes = sceneTicketService.queryByParams(map);
            if (!ValidUtil.isEmpty(scenes) && !ValidUtil.isEmpty(scenes.get(0).get("placard"))) {
                String placard = scenes.get(0).get("placard").toString();
                ajaxMsg.setDatas(placard);
            }
        } else {
            List<Dictionary> list = dictionaryService.getDicByKeyNo(type);
            if (!ValidUtil.isEmpty(list)) {
                ajaxMsg.setDatas(list.get(0).getKeyValue());
            }
        }

        return ajaxMsg;
    }
}
